package com.wingy.myrecyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {

    private List<Imagetext> imagetextList = new ArrayList<>();

    private void init() {
        for(int i = 0; i<5; i++){
            Imagetext a = new Imagetext("AAA", R.mipmap.ic_launcher);
            imagetextList.add(a);
            Imagetext b = new Imagetext("BBB", R.mipmap.ic_launcher);
            imagetextList.add(b);
            Imagetext c = new Imagetext("CCC", R.mipmap.ic_launcher);
            imagetextList.add(c);
            Imagetext d = new Imagetext("DDD", R.mipmap.ic_launcher);
            imagetextList.add(d);
            Imagetext e = new Imagetext("EEE", R.mipmap.ic_launcher);
            imagetextList.add(e);
            Imagetext f = new Imagetext("FFF", R.mipmap.ic_launcher);
            imagetextList.add(f);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);

        init();

        RecyclerView recyclerView = findViewById(R.id.recycle_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //横向
        //layoutManager.setOrientation(layoutManager.HORIZONTAL);
        //网格布局
        //GridLayoutManager layoutManager = new GridLayoutManager(this, 3);

        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

        recyclerView.setLayoutManager(layoutManager);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(imagetextList);
        recyclerView.setAdapter(adapter);
    }

}
